package com.test.kupi.page.object;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class PageSearch extends Page {

	@FindBy(name = "str")
	private WebElement searchField;
	
	@FindBy(css = "input.button.big")
	private WebElement searchButton;
	
	@FindBy(linkText = "По цене")
	private WebElement priceFilter;
	
//	@FindBy(linkText = "По цене")
//	private WebElement priceFilter;
//
//	@FindBy(linkText = "По цене")
//	private WebElement priceFilter;

	
	public PageSearch(WebDriver driver) {
        PageFactory.initElements(driver, this);
        this.driver = driver;
    }
	
	public PageSearch searchItem(String text) {
		searchField.clear();;
		searchField.sendKeys(text);
		return this;
	}
	
	public PageSearch clickSearchBut() {
		searchButton.click();
		return this;
	}
	
	public PageSearch sortPrice(String text) {
		if (text.equals("ASC"))		{
			do {
				priceFilter.click();
			}
			while (isElementPresent(By.xpath("//i[@class = 'b-icon icon-up']")) != true);
		}
		if (text.equals("DESC"))		{
			do {
				priceFilter.click();
			}
			while (isElementPresent(By.xpath("//i[@class = 'b-icon icon-up']")) == true);
		}
		return this;
	}
}
